﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.Threading;

namespace SVAccountingWebUI
{
    public partial class Base : System.Web.UI.MasterPage
    {
        
        #region Public Properties
        public TreeView SiteMapTreeView
        {
            get { return TreeView1; }
            set { TreeView1 = value; }
        }

        public string MessageText
        {
            get { return lblMasterMessage.Text; }
            set { lblMasterMessage.Text = value; }
        }

        public Color MessageColor
        {
            get { return lblMasterMessage.ForeColor; }
            set { lblMasterMessage.ForeColor = value; }
        }
        #endregion

        #region Protected Methods

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.User.Identity.IsAuthenticated)
            {
                IniSiteMap();
                lblLoginInfo.Visible = true;
            }
            MessageText = string.Empty;
            MessageColor = Color.Black;
        }

        protected void LogOut(object sender, EventArgs e)
        {
            Session.Abandon();
            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage();

        }

        #endregion

        #region Private Methods
        private void IniSiteMap()
        {
            if (Roles.GetRolesForUser().Length > 0)
            {
                switch (Roles.GetRolesForUser()[0])
                {
                    case "Administrator":
                        {
                            TreeView1.DataSourceID = SiteMapDataSource2.ID;
                            break;
                        }
                    case "Accountant":
                        {
                            TreeView1.DataSourceID = SiteMapDataSource3.ID;
                            break;
                        }
                    default:
                        {
                            TreeView1.DataSourceID = SiteMapDataSource1.ID;
                            break;
                        }
                }
            }
            else
                TreeView1.DataSourceID = SiteMapDataSource1.ID;
            TreeView1.DataBind();
        }
        #endregion

        protected void RequestLanguageChange_Click(object sender, EventArgs e)
        {
            ImageButton senderLink = sender as ImageButton;

            //store requested language as new culture in the session
            Session["culture"] = senderLink.CommandArgument;

            //reload last requested page with new culture
            Server.Transfer(Request.Path);
        }

    }
}
